<script lang="ts" setup name="CallbackPatch">
import Message from '@/components/message'
import useStore from '@/store'
import { ref } from 'vue'
import { useRouter } from 'vue-router'
const router = useRouter()
const { user } = useStore()

const form = ref({
  account: '',
  mobile: '',
  code: '',
  password: ''
})
//获取openID
let openId = ''
if (QC.Login.check()) {
  QC.Login.getMe((id) => {
    openId = id
  })
}
//获取手机验证码
function code() {
  // if (form.value.mobile === '') return
  user.sendQQPathMsg(form.value.mobile)
  Message.success('获取验证码成功')
}
async function send() {
  await user.qqPatchLogin({
    openId,
    mobile: form.value.mobile,
    code: form.value.code,
    account: form.value.account,
    password: form.value.password
  })
  Message.success('注册成功')
  router.push('/')
}
</script>
<template>
  <div class="xtx-form">
    <div class="xtx-form-item">
      <div class="field">
        <i class="icon iconfont icon-user"></i>
        <input v-model="form.account" class="input" type="text" placeholder="请输入用户名" />
      </div>
      <div class="error"></div>
    </div>
    <div class="xtx-form-item">
      <div class="field">
        <i class="icon iconfont icon-phone"></i>
        <input v-model="form.mobile" class="input" type="text" placeholder="请输入手机号" />
      </div>
      <div class="error"></div>
    </div>
    <div class="xtx-form-item">
      <div class="field">
        <i class="icon iconfont icon-code"></i>
        <input v-model="form.code" class="input" type="text" placeholder="请输入验证码" />
        <span class="code" @click="code">发送验证码</span>
      </div>
      <div class="error"></div>
    </div>
    <div class="xtx-form-item">
      <div class="field">
        <i class="icon iconfont icon-lock"></i>
        <input v-model="form.password" class="input" type="password" placeholder="请输入密码" />
      </div>
      <div class="error"></div>
    </div>
    <!-- <div class="xtx-form-item">
      <div class="field">
        <i class="icon iconfont icon-lock"></i>
        <input class="input" type="password" placeholder="请确认密码" />
      </div>
      <div class="error"></div>
    </div> -->
    <a href="javascript:;" class="submit" @click="send">立即提交</a>
  </div>
</template>

<style scoped lang="less">
.code {
  position: absolute;
  right: 0;
  top: 0;
  line-height: 50px;
  width: 80px;
  color: #999;
  &:hover {
    cursor: pointer;
  }
}
</style>
